package com.yuandian.customer.perception.controller;

import com.yuandian.api.customer_perception.po.BusinessPerformanceParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.customer.perception.service.IBusinessPerformanceService;
import com.yuandian.enums.TableNameEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 说明：业务性能指标controller
 * @Author yanjun
 * @Date 2021/12/20 10:23
 */
@RestController
@RequestMapping("/performance")
public class BusinessPerformanceController {


    @Autowired
    private IBusinessPerformanceService businessPerformanceService;

    /**
     * 查询业务性能指标列表过滤项
     * @param params 业务性能指标查询参数对象
     * @return 通用返回对象
     */
    @PostMapping("/queryBusinessPerformanceOptions")
    public R queryBusinessPerformanceOptions(@RequestBody BusinessPerformanceParams params) {
        params.setTableName(TableNameEnum.BUSINESS_URL_API_STAT_M.getName());
        return businessPerformanceService.queryBusinessPerformanceOptions(params);
    }

    /**
     * 查询业务性能指标列表
     * @param params 业务性能指标查询参数对象
     * @return 通用返回对象
     */
    @PostMapping("/queryBusinessPerformanceList")
    public R queryBusinessPerformanceList(@RequestBody BusinessPerformanceParams params) {
        return businessPerformanceService.queryBusinessPerformanceList(params);
    }

    /**
     * 下载业务性能指标列表
     * @param params 业务性能指标查询参数对象
     * @param response 响应上下文
     */
    @PostMapping("/exportBusinessPerformanceList")
    public R exportBusinessPerformanceList(@RequestBody BusinessPerformanceParams params,
                                              HttpServletRequest request, HttpServletResponse response) {
        // 设置浏览器类型
        String agent = request.getHeader("User-Agent");
        if (agent.toLowerCase().contains("firefox")) {
            params.setBrowser("firefox");
        } else {
            params.setBrowser("common");
        }
        businessPerformanceService.exportBusinessPerformanceList(params, response);
        return null;
    }

    /**
     * 查询用户操作行为列表
     * @param params 业务性能指标查询参数对象
     * @return 统一返回对象
     */
    @PostMapping("/queryOperatorBehaviorList")
    public R queryOperatorBehaviorList(@RequestBody BusinessPerformanceParams params) {
        return businessPerformanceService.queryOperatorBehaviorList(params);
    }

    /**
     * 查询业务功能图表信息
     * @param params 业务性能指标查询参数对象
     * @return 统一返回对象
     */
    @PostMapping("/queryBusinessFunctionChartData")
    public R queryBusinessFunctionChartData(@RequestBody BusinessPerformanceParams params) {
        return businessPerformanceService.queryBusinessFunctionChartData(params);
    }
}
